<?php

namespace app\common\model\check;

use app\common\model\MoneyLog;
use app\common\model\ScoreLog;
use think\Model;

class Order extends Model
{

    // 表名
    protected $name = 'store_order';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'add_time';
    protected $updateTime = 'up_time';
    // 追加属性
    protected $append = [

    ];
    /**
     * 支付类型
     * @var string[]
     */
    protected $pay_type = [
        1 => 'weixin',
        2 => 'yue',
        3 => 'offline',
        4 => 'alipay'
    ];
    /**
     * 套餐时长
     * @var string[]
     */
    public static $duration = [
        1 => '单次',
        2 => '半年',
        3 => '一年',
    ];
    /**
     * 套餐规格
     * @var string[]
     */
    public static $specifications = [
        1 => '630kg及以下',
        2 => '800kg',
        3 => '1000kg',
    ];
    /**
     * 套餐规格
     * @var string[]
     */
    public static $package = [
        1 => '临时清洁',
        2 => '基础清洁',
        3 => '养生清洁',
        4 => '深度清洁',
    ];
    /**
     * 订单状态
     * @var string[]
     */
    public static $status_name = [
        12 => '服务中',
        13 => '服务完成',
        14 => '已取消',
        3 => '待评价',
        4 => '已完成',
        5 => '售后',
        6 => '已取消',
        7 => '已删除',
        8 => '待服务',
        9 => '待支付',
        10 => '待接单',
        11 => '待确认',
        15 => '待退款',
        0 => '待支付',
        1 => '待接单',
        2 => '待服务',
    ];

    public function getOriginData()
    {
        return $this->origin;
    }


    public function getGenderList()
    {
        return ['1' => __('Male'), '0' => __('Female')];
    }

    public function getStatusList()
    {
        return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
    }


    public function getPrevtimeTextAttr($value, $data)
    {
        $value = $value ? $value : ($data['prevtime'] ?? "");
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    public function getLogintimeTextAttr($value, $data)
    {
        $value = $value ? $value : ($data['logintime'] ?? "");
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    public function getJointimeTextAttr($value, $data)
    {
        $value = $value ? $value : ($data['jointime'] ?? "");
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setPrevtimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }

    protected function setLogintimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }

    protected function setJointimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }

    protected function setBirthdayAttr($value)
    {
        return $value ? $value : null;
    }

    public function school()
    {
        return $this->belongsTo('SchoolClass', 'school_class_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function trusteeshipType()
    {
        return $this->belongsTo('TrusteeshipType', 'tg_type_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function myclass()
    {
        return $this->belongsTo('MyClass', 'my_class_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

}
